<!DOCTYPE html> 
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hello, World</title>
<style type="text/css">html{height:100%}body{height:100%;margin:0px;padding:0px}#container{height:100%}</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=kYNBHZVjWZTHtx7d0itDoZUb"></script>
<script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
</head>
<body onload="initMapOnCompsite()">
<div id="container"></div>
<script type="text/javascript">
var routeflag=false;
var clickcount=0; 
var trace;
var starttrace;
var endtrace;
var marker1;
var marker2;
var trace_location="";
var map = new BMap.Map("container");


function initMapOnCompsite(){
	map.centerAndZoom(new BMap.Point(104.072227, 30.663468), 15);    
	//map.disableDoubleClickZoom();
	//map.centerAndZoom(point, 18);
}
map.addEventListener("dblclick", function(e){    
 //alert("您双击了地图,经度："+e.point.lng+","+"纬度："+e.point.lat);

 if(clickcount==0){
	starttrace=new BMap.Point(e.point.lng,e.point.lat);
	marker1 = new BMap.Marker(starttrace);
	map.addOverlay(marker1);
 }
 if(clickcount==1){
	endtrace=new BMap.Point(e.point.lng,e.point.lat);
	marker2 = new BMap.Marker(endtrace);
	map.addOverlay(marker2);
	routeflag=true;
 }
 trace=new BMap.Point(e.point.lng,e.point.lat);
 clickcount++;
 
if(routeflag){
	//alert("进到导航");
	var driving = new BMap.DrivingRoute(map, {
		renderOptions: {
			map: map,
			enableDragging : true //起终点可进行拖拽
		},  
	});
	driving.search(starttrace, endtrace); 
	driving.setSearchCompleteCallback(function(){
    var pts = driving.getResults().getPlan(0).getRoute(0).getPath();    //通过驾车实例，获得一系列点的数组
	//alert("pts.length="+pts.length);
	for (var i=0;i<pts.length;i++){
		var location=pts[i].lng+","+pts[i].lat+"A";
		trace_location+=location;
	}
	//alert("trace_location.length="+trace_location.length);
	var polyline = new BMap.Polyline(pts);     
	map.addOverlay(polyline);
	map.removeOverlay(marker1);
	map.removeOverlay(marker2);
	testjava(pts.length)
	});
}
});
function testjava(tracecount){
	var msg=callhtml(trace_location,tracecount);
	trace_location="";
	//alert(msg);
}

</script>
</body>
</html>